# Contributor: Mehdi Chinoune <mehdi.chinoune@hotmailcom>

_realname=CLI11
pkgbase=mingw-w64-${_realname,,}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname,,}")
pkgver=2.3.2
pkgrel=1
pkgdesc="Command line parser for C++11 (mingw-w64)"
arch=(any)
mingw_arch=('mingw64' 'mingw32' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
url="https://github.com/CLIUtils/CLI11"
license=(BSD)
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-ninja")
source=(${url}/archive/v${pkgver}/${_realname}-${pkgver}.tar.gz)
noextract=("${_realname}-${pkgver}.tar.gz")
sha256sums=('aac0ab42108131ac5d3344a9db0fdf25c4db652296641955720a4fbe52334e22')

prepare() {
  rm -rf ${_realname}-${pkgver}
  tar -xzf ${_realname}-${pkgver}.tar.gz || true
}

build() {
  [[ -d "${srcdir}"/build-${MSYSTEM} ]] && rm -rf "${srcdir}"/build-${MSYSTEM}
  mkdir -p "${srcdir}"/build-${MSYSTEM} && cd "${srcdir}"/build-${MSYSTEM}

  declare -a extra_config
  if check_option "debug" "n"; then
    extra_config+=("-DCMAKE_BUILD_TYPE=Release")
  else
    extra_config+=("-DCMAKE_BUILD_TYPE=Debug")
  fi

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake \
    -Wno-dev \
    -G"Ninja" \
    -DCMAKE_INSTALL_PREFIX="${MINGW_PREFIX}" \
    ${extra_config[@]} \
    -DCLI11_BUILD_TESTS=OFF \
    -DCLI11_BUILD_EXAMPLES=OFF \
    ../${_realname}-${pkgver}

  ${MINGW_PREFIX}/bin/cmake --build .
}

package() {
  cd "${srcdir}"/build-${MSYSTEM}
  DESTDIR="${pkgdir}" ${MINGW_PREFIX}/bin/cmake --install .

  install -Dm644 "${srcdir}"/${_realname}-${pkgver}/LICENSE -t "${pkgdir}"${MINGW_PREFIX}/share/licenses/${_realname,,}/
}
